package main.java.model;

public class AnalogicalSwitch implements Runnable {
	
	//static final variables to sleep time
    private static final int SLEEP = 20000;

    private boolean isClosed;
    
    /**
     * Constructor AnalogicalSwitch 
     */
    public AnalogicalSwitch() {
        this.isClosed = false;
    }
    
    public String positionToString() {
        //If it is closed
        if (isClosed) { 
            return "Closed";
        } else { 
            return "Open";
        }
    }

    /**
     * Run the thread action
     */
    @Override
    public void run() {
        try {
            //Set to closed
            setClosed(true); 
            
            //20 seconds run in back
            Thread.sleep(SLEEP); 
            
            //Set back to closed
            setClosed(false);
        } catch (InterruptedException e) {
        }
    }

    public boolean isClosed() {
        return isClosed;
    }

    public void setClosed(boolean isClosed) {
        this.isClosed = isClosed;
    }
}
